#include "threadPoolReview.h"

class MyTask : public Task
{
public:
	MyTask(int start, int end):start_(start), end_(end)
	{

	}
	Any run()
	{
		std::cout << "tid:" << std::this_thread::get_id() << "start" << std::endl;
		std::this_thread::sleep_for(std::chrono::seconds(5));
		int sum = 0;
		for (int i = start_; i <= end_; ++i)
		{
			sum += i;
		}
		return sum;
	}
private:
	int start_;
	int end_;
};

int main()
{

	{
		ThreadPool pool;
		//pool.setTaskQueMaxSize(4);
		pool.setPoolMode(Pool_Mode::CACHED_MODE);
		pool.startPool(4);

		Result res1 = pool.submitTask(std::make_shared<MyTask>(1, 10000));
		Result res2 = pool.submitTask(std::make_shared<MyTask>(10001, 20000));
		Result res3 = pool.submitTask(std::make_shared<MyTask>(20001, 30000));
		pool.submitTask(std::make_shared<MyTask>(20001, 30000));
		pool.submitTask(std::make_shared<MyTask>(20001, 30000));
		pool.submitTask(std::make_shared<MyTask>(20001, 30000));
		pool.submitTask(std::make_shared<MyTask>(20001, 30000));
		pool.submitTask(std::make_shared<MyTask>(20001, 30000));
		/*pool.submitTask(std::make_shared<MyTask>(20001, 30000));
		pool.submitTask(std::make_shared<MyTask>(20001, 30000));
		pool.submitTask(std::make_shared<MyTask>(20001, 30000));
		pool.submitTask(std::make_shared<MyTask>(20001, 30000));*/
		/*int num1 = res1.get().cast<int>();
		int num2 = res2.get().cast<int>();
		int num3 = res3.get().cast<int>();

		std::cout << "result:" << num1 + num2 + num3 << std::endl;*/
	}


	getchar();
	return 0;
}